# -*- coding: utf-8 -*-
"""
@Time ： 2023/7/2 22:25
@Auth ： 叶东宇
@File ：ValidParentheses.py
"""

class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        print(len(s))
        dic = {"(":")", "[":"]", "{":"}"}
        stack = MyStackUsingQueue()
        for i in s:
            if i in dic:
                stack.push(i)
            else:
                s_tmp = stack.pop()
                if s_tmp in dic:
                    if i!=dic[s_tmp]:
                        return False
                else:
                    return False
        if stack.empty():
            return True
        else:
            return False
class MyStackUsingQueue:
    def __init__(self):

        self.queue_in = []
        self.queue_out = []

    def push(self, x):
        self.queue_in.append(x)

    def pop(self):
        if self.empty():
            return None
        if len(self.queue_in) == 1:
            return self.queue_in.pop(0)
        elif len(self.queue_in) > 1:
            for i in range(len(self.queue_in)-1):
                self.queue_out.append(self.queue_in.pop(0))
            tmp = self.queue_in.pop(0)
            # for i in range(len(self.queue_out)):
            #     self.queue_in.append(self.queue_out.pop(0))
            self.queue_in, self.queue_out = self.queue_out, self.queue_in
            return tmp

    def top(self):
        tmp = self.pop()
        self.queue_in.append(tmp)
        return tmp

    def empty(self):
        return len(self.queue_in)==0 and len(self.queue_out)==0

if __name__ == "__main__":
    s = "{}"
    solution = Solution()
    print(solution.isValid(s))